package com.ruoyi.cost.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cost.domain.VouVarianceItem;
import com.ruoyi.cost.service.IVouVarianceItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 凭证差异项Controller
 * 
 * @author 王志旸
 * @date 2024-07-09
 */
@RestController
@RequestMapping("/cost/vouitem")
public class VouVarianceItemController extends BaseController
{
    @Autowired
    private IVouVarianceItemService vouVarianceItemService;

    /**
     * 查询凭证差异项列表
     */
    // @PreAuthorize("@ss.hasPermi('cost:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(VouVarianceItem vouVarianceItem)
    {
        startPage();
        List<VouVarianceItem> list = vouVarianceItemService.selectVouVarianceItemList(vouVarianceItem);
        return getDataTable(list);
    }

    /**
     * 导出凭证差异项列表
     */
    // @PreAuthorize("@ss.hasPermi('cost:item:export')")
    @Log(title = "凭证差异项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VouVarianceItem vouVarianceItem)
    {
        List<VouVarianceItem> list = vouVarianceItemService.selectVouVarianceItemList(vouVarianceItem);
        ExcelUtil<VouVarianceItem> util = new ExcelUtil<VouVarianceItem>(VouVarianceItem.class);
        util.exportExcel(response, list, "凭证差异项数据");
    }

    /**
     * 获取凭证差异项详细信息
     */
    // @PreAuthorize("@ss.hasPermi('cost:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(vouVarianceItemService.selectVouVarianceItemById(id));
    }

    /**
     * 新增凭证差异项
     */
    // @PreAuthorize("@ss.hasPermi('cost:item:add')")
    @Log(title = "凭证差异项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VouVarianceItem vouVarianceItem)
    {
        return toAjax(vouVarianceItemService.insertVouVarianceItem(vouVarianceItem));
    }

    /**
     * 修改凭证差异项
     */
    // @PreAuthorize("@ss.hasPermi('cost:item:edit')")
    @Log(title = "凭证差异项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VouVarianceItem vouVarianceItem)
    {
        return toAjax(vouVarianceItemService.updateVouVarianceItem(vouVarianceItem));
    }

    /**
     * 删除凭证差异项
     */
    // @PreAuthorize("@ss.hasPermi('cost:item:remove')")
    @Log(title = "凭证差异项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(vouVarianceItemService.deleteVouVarianceItemByIds(ids));
    }
}
